<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改学生信息')"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-role-edit" th:object="${student}">
        <input id="studentId" name="studentId" th:field="*{studentId}" type="hidden"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">学生名称：</label>
            <div class="col-sm-8">
                <input class="form-control" id="studentName" name="studentName" required th:field="*{studentName}"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">入学成绩：</label>
            <div class="col-sm-8">
                <input class="form-control" id="studentGrade" name="studentGrade" required th:field="*{studentGrade}"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出生日期：</label>
            <div class="col-sm-8">
                <input class="form-control" id="studentBirthday" name="studentBirthday" placeholder="年-月-日"
                       required th:field="*{studentBirthday}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">学生性别：</label>
            <div class="col-sm-8">
                <select class="form-control" id="studentSex" name="studentSex" required th:field="*{studentSex}">
                    <option value="0">男</option>
                    <option value="1">女</option>
                    <option value="2">未知</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">所在系：</label>
            <div class="col-sm-8">
                <select class="form-control" id="departmentId" name="departmentId"
                        required th:field="*{departmentId}" th:with="type=${@dept.getDepartmentId()}">
                    <option th:each="dept : ${type}" th:text="${dept.deptName}" th:value="${dept.deptId}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<script type="text/javascript">
    $(function () {
        $("#studentBirthday").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    });

    function edit() {
        var studentId = $("input[name='studentId']").val();
        var studentName = $("input[name='studentName']").val();
        var studentGrade = $("input[name='studentGrade']").val();
        var studentBirthday = $("input[name='studentBirthday']").val();
        var studentSex = $("#studentSex").val();
        var departmentId = $("#departmentId").val();
        $.ajax({
            cache: true,
            type: "POST",
            url: ctx + "project/student/updateStudent",
            data: {
                "studentId": studentId,
                "studentName": studentName,
                "studentGrade": studentGrade,
                "studentBirthday": studentBirthday,
                "studentSex": studentSex,
                "departmentId": departmentId
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallback(data);
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }
</script>
</body>
</html>
